
#include "compile.hpp"
#include <iostream>
#include "runner.hpp"
#include <locale>
#include "compile_run.hpp"
#include "../comm/httplib.h"
// 注意注意json中文乱码，后面需要修改****
//  ***************************************
//  ****************************************
//  ***************************************
//
using namespace ns_compile_and_run;
using namespace httplib;
void Usage(const std::string &proc)
{
  std::cerr << "Usage" << "\n\r" << proc << " :port" << std::endl;
}
int main(int argc, char *argv[])
{
  if (argc != 2)
  {
    Usage(argv[0]);
    return 1;
  }
  Server svr;
  Response test;
  test.set_content("hello httplib ,你好 httplib!", "text/plain;");
  svr.Get("/hello", [](const Request &req, Response &resp)
          {
    //用来进行基本测试
    resp.set_content("hello httplib ,你好 httplib!","text/plain;charset=utf-8"); });
  svr.Post("/compile_and_run", [](const Request &req, Response &resp)
           {
      std::string in_json=req.body;
      std::string out_json;
      CompileAndRun::Start(in_json,&out_json);
      resp.set_content(out_json,"application/json;charset=utf-8"); });
  svr.listen("0.0.0.0", atoi(argv[1])); // 启动服务
  // 提供的编译服务，打包形成一个网络服务

  // cpp_httplib
  // in_json:{"code":"#include...","input":"","cpu_limit":1,"mem_limit":"20"}
  // out_json:{"status":"0","reason":"","stdout":"","stderr":""}
  // std::string  in_json;
  // Json::Value in_value;
  // in_value["code"]=R"(#include<iostream>
  // int main(){
  // std::cout<<"你好,我是大帅哥"<<std::endl;
  // return 0;
  // })";
  // in_value["input"]="大苏打";
  // in_value["cpu_limit"]=1;
  // in_value["mem_limit"]=10240*3;
  // Json::FastWriter writer;
  // in_json=writer.write(in_value);
  // std::cout<<in_json<<std::endl;
  // std::string out_json;
  // CompileAndRun::Start(in_json,&out_json);
  // std::cout<<out_json<<std::endl;

  return 0;
}